<?php
/**
 * 字符串截取
 * @param $str
 * @param $length
 * @param string $sign
 * @param string $encoding
 * @return string
 */
function mbSubstr($str, $length, $sign = '...', $encoding = 'utf-8')
{
    $ole_leng = mb_strlen($str, $encoding);
    if ($ole_leng <= $length) {
        return $str;
    }
    $new_str = mb_substr($str, 0, $length, $encoding);
    $new_str .= $sign;
    return $new_str;
}

/**
 * 格式化价格
 * @param $money
 * @return string
 */
function changePrice($money)
{
    return number_format($money / 100, 2);
}

/**
 * 获取随机字符串
 * @param int $length
 * @return string
 */
function createNoncestr($length = 16)
{
    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $str = "";
    for ($i = 0; $i < $length; $i++) {
        $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
    }
    return $str;
}
